package com.md.drcs.dicom.dao;

import com.md.common.utils.dao.MyMapper;
import com.md.drcs.dicom.dto.PatientOpenidDTO;
import com.md.drcs.dicom.entity.UserPatientEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserPatientDao extends MyMapper<UserPatientEntity> {

    @Select("select id, user_id, patient_id from u_user_patient where user_id = #{userId}")
    List<UserPatientEntity> findByUserId(Integer userId);

    @Delete("delete from u_user_patient where user_id = #{userId} and patient_id = #{patientId}")
    void deletePatient(@Param("patientId") Integer patientId, @Param("userId") Integer userId);

    @Select("select id, user_id, patient_id from u_user_patient where user_id = #{userId} and patient_id = #{patientId}")
    UserPatientEntity findByUserPatient(@Param("userId") Integer userId, @Param("patientId") Integer patientId);

    @Select("<script>" +
            "select up.user_id, u.openid, up.patient_id from u_user_patient up" +
            " inner join u_user u on (up.user_id = u.id)" +
            " where up.patient_id in " +
            " <foreach collection='patientIds' item='pid' open='(' separator=',' close=')'>" +
            " #{pid}" +
            " </foreach>" +
            "</script>")
    List<PatientOpenidDTO> findByPatientIds(@Param("patientIds") List<Long> patientIds);

}
